/**
 * 
 */
package com.planner.core.service.core.stop;

import java.util.ArrayList;
import java.util.List;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import com.planner.core.dao.NodeDAO;
import com.planner.core.dao.NodeDAOImpl;
import com.planner.core.service.rest.vo.Stop;
import com.planner.core.vo.GraphNode;

/**
 * @author Sangharsh
 *
 */
public class StopServiceImpl implements StopService {
	
	private NodeDAO nodeDAO;
	
	private static final Log LOG = LogFactory.getLog(StopServiceImpl.class);
	public StopServiceImpl(){
		nodeDAO = NodeDAOImpl.INSTANCE;
	}
	
	/* (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#add(com.planner.core.vo.GraphNode)
	 */
	public void add(GraphNode node) {
		nodeDAO.add(node);
	}
	/*
	 * (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#addAll(java.util.List)
	 */
	public void addAll(List<GraphNode> nodes) {
		for(GraphNode node : nodes){
			nodeDAO.add(node);
		}
	}
	/* (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#deleteNode(long)
	 */
	public void deleteNode(long id) {
		nodeDAO.deleteNode(id);
	}

	/* (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#getAllNodes()
	 */
	public List<GraphNode> getAllNodes() {
		LOG.info("Retrieving all nodes");
		return nodeDAO.getAllNodes();
	}

	/* (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#getNode(long)
	 */
	public GraphNode getNode(long id) {
		return nodeDAO.getNode(id);
	}

	/* (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#updateNode(com.planner.core.vo.GraphNode)
	 */
	public void updateNode(GraphNode node) {
		nodeDAO.updateNode(node);
	}

	/*
	 * (non-Javadoc)
	 * @see com.planner.core.service.core.stop.StopService#getNode(java.lang.String)
	 */
	public GraphNode getNode(String code) {
		return nodeDAO.getNode(code);
	}

	public List<Stop> getAllStops() {
		List<Stop> stops = new ArrayList<Stop>();
		for(GraphNode node: getAllNodes()){
			stops.add(new Stop(node.getId(), node.getName()));
		}
		return stops;
	}

}
